package com.xjy.rpc.netty.handler.client;

import com.xjy.rpc.cache.ChannelCache;
import com.xjy.rpc.cache.RpcRequestCache;
import com.xjy.rpc.netty.message.RpcResponse;
import com.xjy.rpc.netty.promise.RpcFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class ClientMessageHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        RpcResponse response = (RpcResponse) msg;
        RpcFuture<RpcResponse> future = RpcRequestCache.REQUEST_MAP.get(response.getRequestId());
        future.getPromise().setSuccess(response);
    }
}
